<template>
    <el-dialog :visible.sync="visible" width="1000px" :append-to-body="true" title="选择商品">
        <div style="height:60vh">
			<div>
				<el-input placeholder="请输入商品名称或编码或商户" style="width: 260px;margin-right: 10px;" v-model="searchParamCp.keyword"
					size="mini" clearable>
				</el-input>
				<el-button type="primary" size="mini" @click="searchs()">搜索</el-button>
				<el-button size="mini" @click="reset()">重置</el-button>
			</div>
            <!-- <goodschoose :initalSelection="value" ref="goodschoose"></goodschoose> -->
			<el-table  row-key="id" 
			      :data="list" height="90%" @selection-change="onSelectionChange">
				  <el-table-column :reserve-selection="true" type="selection" width="40"> </el-table-column>
			      <el-table-column label="商品图片">
			      	<template slot-scope="{row}">
			      		<el-image style="width:60px;height:60px" :src="row.url" :preview-src-list="[row.url]">
			      		</el-image>
			      	</template>
			      </el-table-column>
			      <el-table-column align="center" label="商品名称" prop="goods_name" />
			      <el-table-column align="center" label="商品分类" prop="cate_name" />
			      <el-table-column align="center" label="售价" prop="goods_price_min" />
			      
			      <!-- <el-table-column align="center" label="划线价" prop="goods_price_min" /> -->
			      <el-table-column align="center" label="原价" prop="line_price_max" />
			      <!-- check_status 0待审 1通过-->
			      <el-table-column align="center" label="审核状态" prop="status">
			      	<template slot-scope="{ row }">
			      		<el-tag v-if="row.check_status==0">待审核</el-tag>
			      		<el-tag  v-if="row.check_status==1" type="success">已通过</el-tag>
			      	</template>
			      </el-table-column>
			      <el-table-column align="center" label="启用状态" prop="status">
			      	<!-- status状态  10上架 20下架 -->
			      	<template slot-scope="{ row }">
			      		<el-switch v-model="row.status == 20 ? false : true" disabled>
			      		</el-switch>
			      		<!-- <el-switch v-model="row.status" active-value="10" inactive-value="20"></el-switch> -->
			      	</template>
			      </el-table-column>
			    </el-table>
			<el-pagination class="main-pagination" :current-page.sync="page" :page-size="limit" :total="total"
			    @current-change="onCurrentChange" layout="total,jumper,prev,pager,next"></el-pagination>
        </div>
        <template #footer>
            <el-button @click="close">取 消</el-button>
            <el-button type="primary" @click="confirm">确 定</el-button>
        </template>
    </el-dialog>
</template>
<script>
// import storeTable from '@/views/assignment/list/index.vue'
import goodschoose from '../views/merchant/list/index.vue'
import { get, del,post } from "@/assets/js/http.js";
export default{
    components:{goodschoose},
    data(){
        return{
            visible:false,
			total:0,
			page:1,
			list:[],
			limit:15,
			selection:[],
			searchinfo: {
				keyword: '',
				check_status: '',
				status:'',
			},
			searchParamCp: {},
        }
    },
    props:{
        value:{
            type:Array,
            default:()=>[]
        },
		title:{
			type:String,
			defaulit:''
		}
    },
	mounted() {
		this.getlist()
	},
    methods:{
		getlist(){
			get({
				url:'/admin/shop.goods/allGoodsList',
				params: {
				    limit: 15,
				    page: this.page,
					...this.searchinfo,
				}
			}).then(res=>{
				this.list = res.list;
				this.total = res.total;
			})
		},
		//搜索
		searchs() {
			this.page = 1
			this.searchinfo = {
				...this.searchinfo,
				...this.searchParamCp
			}
			this.getlist()
		},
		//重置
		reset() {
			this.searchParamCp = {}
			this.searchinfo = {
				keyword: '',
				check_status: '',
				status:''
			},
				this.getlist()
		},
		onCurrentChange(index) {
		    this.page = index;
		    this.getlist();
		},
		onSelectionChange(selection) {
			this.selection = selection;
			console.log(this.selection,'selection')
		},
        open(){
            this.visible = true;
        },
        close(){
            this.visible = false;
        },
        confirm(){
            this.$emit('input',this.selection.map(item=>item.id))
            this.$emit('confirm',this.selection)
            this.close()
        }
    }
}
</script>